package thread;

import java.io.IOException;

/**
 * @Author zhangxuhui
 * @Date 2023/12/21
 * @email zxh_1633@163.com
 * this引用逸出是指，在类的构造方法中发布该类的对象，
 * 导致尚未构造完全的对象被其他线程访问。
 * 不要在构造器中启动线程
 */
public class ThisEscape {
    private int num = 8;

    public ThisEscape(){
        new Thread(()->{
            System.out.println(this.num);
        }).start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws IOException {
        new ThisEscape();
        System.in.read();
    }
}
